package com.htdc.web.controller;

import com.htdc.web.bean.User;
import com.htdc.web.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * User: Sfx
 * Date: 2018/9/4 0004
 * Time: 下午 7:22
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public String login(String account, String password, HttpSession session) {
        User user = userService.login(account, password);
        if(user!=null){
            session.setAttribute("user",user);
            System.out.println(user);
            return "index";
        }
        session.setAttribute("loginMsg","账号或密码不正确");
        return "login";
    }
    @RequestMapping("/toLogin")
    public String toLogin(){
        return "login";
    }
}
